package com.huike.pmps.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huike.pmps.dao.DictionaryDao;
import com.huike.pmps.model.dto.common.PageInfo;
import com.huike.pmps.model.entity.Dictionary;
import com.huike.pmps.model.entity.Member;
import com.huike.pmps.model.vo.PageResult;
import com.huike.pmps.model.vo.Result;
import com.huike.pmps.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {
    @Autowired
    DictionaryDao dictionaryDao;

    /**
     * 根据字典类型type进行查询
     *
     * @param type
     * @return
     */
    @Override
    public Result selectByType(Integer type) {
        QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
        if (type != null) {
            queryWrapper.eq("type", type);
        }
        return Result.success(dictionaryDao.selectList(queryWrapper));
    }

    @Override
    public List<Dictionary> selectListByType(Integer type) {
        QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
        if (type != null) {
            queryWrapper.eq("type", type);
        }
        return dictionaryDao.selectList(queryWrapper);
    }

    /**
     * 根据字典 keycode和字典类型type进行查询
     *
     * @param KeyCode
     * @param type
     * @return
     */
    @Override
    public Dictionary selectByKeyCode(String KeyCode, Integer type) {
        QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(KeyCode)) {
            queryWrapper.eq("key_code", KeyCode);
        }
        if (type != null) {
            queryWrapper.eq("type", type);
        }
        return dictionaryDao.selectOne(queryWrapper);
    }

    /**
     * 根据主键id进行查询 返回实体Dictionary
     *
     * @param id
     * @return
     */
    @Override
    public Dictionary selectByOne(String id) {
        return dictionaryDao.selectById(id);
    }

    @Override
    public Dictionary selectByOne(String name, Integer type) {
        QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(name)) {
            queryWrapper.like("name", name);
        }
        if (type != null) {
            queryWrapper.eq("type", type);
        }
        return dictionaryDao.selectOne(queryWrapper);
    }

    /**
     * 加载所有字典数据
     *
     * @return
     */
    @Override
    public List<Dictionary> selectList() {
        return dictionaryDao.selectList(null);
    }


}
